<?php
ini_set('session.bug_compat_warn','off');

include("mainfile.php");

// ADMIN DATA
include("admin/admin.php");
    $admin = new Admin;
        $admin->init();

$content = "";

if ($admin->valid)
{
    $actions = array();
        $actions = explode(":", $_POST['action']);
            $op     = $actions[0]; if ($op == "") { $op = $_GET['op']; }
                $action = $actions[1]; if ($action == "") { $action = $_GET['action']; }
                $id     = $actions[2]*1; if ($id == 0) { $id = $_GET['id']*1; }
                $target = $_POST['target'];

        if ($op != "logout")
        {
            $admin->setLang();
        include("admin/menu.php");
            $navmenu = adminMenu();
                $tpl->file ="admin.tpl";

            if ($op == "d") // Directory action
            {
                include("admin/includes/filemanager.php");
                $dir = new Dir;
                    $content.= $dir->init($id);

                        if ($action == "new")
                        {
                            $content.= $dir->createNewDirectory($target);
                                $content.= $dir->go($dir->id);
                        }
                        elseif ($action == "rename")
                        {
                            $content.= $dir->renameDirectory($target);
                                $content.= $dir->go($dir->parent);
                        }
                        elseif ($action == "delete_all")
                        {
                            $content.= $dir->deleteDirectory($dir->id);
                                $content.= $dir->go($dir->parent);
                        }
                        else
                        {
                            $content.= $dir->go($dir->id);
                        }
            }
                elseif ($op == "p") // Page action
                {
                        include("admin/includes/pagecreator.php");
                $page = new Page;
                    $content.= $page->init($id);

                    if ($action == "rename")
                        {
                            include("admin/includes/filemanager.php");
                    $dir = new Dir;
                        $content.= $dir->init($page->dir);

                            $content.= $page->renamePage($target);
                                $content.= $dir->go($page->dir);
                        }
                        elseif ($action == "delete")
                        {
                            include("admin/includes/filemanager.php");
                    $dir = new Dir;
                        $content.= $dir->init($page->dir);

                            $content.= $page->deletePage($target);
                                $content.= $dir->go($page->dir);
                        }
                        elseif ($action == "save")
                        {
                            $dir         = $_POST['dir']*1;
                                $name        = $_POST['name'];
                                $title       = $_POST['title'];
                                $keywords    = $_POST['keywords'];
								$pagecontent = stripslashes($_POST['pagecontent']);

                                if ($page->id <= 0) // save new page
                                {
                                    $content.= $page->saveNewPage($dir, $name, $title, $keywords, $pagecontent);
                                }
                                else // update existing page
                                {
                                    $content.= $page->updatePage($page->id, $title, $keywords, $pagecontent);
                                }
                        }
                        else
                        {
                            $content.= $page->showForm($id);
                        }
                }
            else
            {
                    $content.= "ADMINBEREICH";
                #include("admin/menu.php");
                #$content.= adminMenu();
            }
        }
        else
        {
            $admin->logout();
            include("admin/login.php");
            $content.= $html->center("<br><br>"._LOGGEDOUT,"red");
                $content.= "<br><br>".loginForm();
            $navmenu = "";
        }
}
else
{
    include("admin/login.php");
        $content.= "<br><br><br><br><br>".loginForm();
        $navmenu = "";
}


// get the template
$tpl->getTpl($tpl->file);
$tpl->replaceCommonTags();
$tpl->replaceTags(array(
TITLE       =>  _ADMINAREA,
CONTENT     =>  $content,
NAVMENU     =>  $navmenu,
NAV_TOP     =>  $common->navMenuTop(),
BOTTOM      =>  $common->Bottom(0),
PAGEROUTE   =>  ""
));
echo $tpl->page;

?>